/*
 * @Author: your name
 * @Date: 2021-10-13 09:29:25
 * @LastEditTime: 2021-10-15 22:16:12
 * @LastEditors: Please set LastEditors
 * @Description: 使得箱子剩余空间最小
 * @FilePath: \luogu\动态规划\模板问题\P1049 装箱问题\3main.cpp
 */
#include<iostream>
using namespace std;
#include<algorithm>

const int VMAX = 20010;
const int NMAX = 40;

int f[VMAX] = {0};

int main(){
    int v,n;
    int a[NMAX];
    cin >> v >> n;

    // cout << "v = " << v << " n = " << n << endl;
    for(int i=1; i<=n; i++){
        cin >> a[i];
        for(int j=v; j>=a[i]; j--){
            if(f[j] < f[j-a[i]]+a[i])
                f[j] = f[j-a[i]]+a[i];
        }
        // cout << "n=" << n << endl;
        // cout << "-- i = " << i << endl;
    }
    cout << v-f[v] << endl;
    return 0;
}
